#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
bool b[14];
bool three(int index, int arr[]) {
	if (index + 2 < 14) {

		int a1 = arr[index];
		int b1 = arr[index + 1];
		int c1 = arr[index + 2];
		if (a1 == b1 && b1 == c1 && b[index] == 0 && b[index + 1] == 0 && b[index + 2] == 0) {
			return true;
		}
	}
	return false;
}
int getnextindex(int index, int arr[]) {
	int i = 1;
	while (index + i < 14) {

		if (arr[index] != arr[index + i] && b[index + i] == 0) {
			return index + i;
		}
		i++;
	}
	return -1;
}


bool work(int arr[]) {

	int i = 0;
	for (int i = 0; i < 13; i++) {
		int all = 0;
		if (i == 12) {
			int ddd = 1;
		}

		if (i == 7) {
			int ddd = 1;
		}
		for (int t = 0; t < 14; t++) {
			b[t] = 0;
		}
		if (arr[i] == arr[i + 1]) {
			b[i] = 1;
			b[i + 1] = 1;
			int k1 = 0;
			while (k1 < 13) {
				if (b[k1] == 1) { k1++; continue; }
				if (three(k1, arr)) {
					k1 += 3;

					all += 1;
					if (all == 4) {
						return true;
					}
					continue;
				}
				else {

					int k2 = getnextindex(k1, arr);
					if (arr[k2] - arr[k1] != 1) {
						break;
					}
					int k3 = getnextindex(k2, arr);

					if (arr[k3] - arr[k2] != 1) {
						break;
					}
					else {
						b[k1] = 1;
						b[k2] = 1;
						b[k3] = 1;
						all += 1;
						k1++;
					}

				}
			}
			//return i;
			//printf("Get %d", i);
		}
	}
	return 0;
}

int main() {
	//int arr[] = { 1,1,1,2,2,2,5,5,5,6,6,6,9,9};
	//work(arr);

	int arr[13];
	int arrx[14];
	for (int i = 0; i < 13; i++) {
		scanf("%d", &arr[i]);

	}

	for (int i = 1; i < 10; i++) {
		bool enter = false;
		for (int j = 0; j < 13; j++) {
			if (i > arr[j]) {
				arrx[j] = arr[j];
			}
			else {
				if (!enter) {
					enter = true;
					arrx[j] = i;
					arrx[j+1] = arr[j];
				}
				else {
					arrx[j + 1] = arr[j];
				}
			}

		}

		if (work(arrx)) {
			printf("%d ",i);
		}
	}
	printf("0");

}